package com.dd.census.tools.excel.test;

import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.dd.census.tools.excel.ExcelImport;

public class Demo {

	public static void main(String[] args) {

		// import0();
		// export0();
		export1();
	}

	public static void import0() {
		try {
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			FileInputStream fs = new FileInputStream(new File("D:\\11111.xlsx"));
			List<DemoEntity> a = new ExcelImport().getList(fs, DemoEntity.class);
			for (int i = 0; i < a.size(); i++) {
				System.out.println(a.get(i).getName() + "/" + a.get(i).getDesc() + "/" + a.get(i).getSum() + "/" + a.get(i).getMoney() + "/" + sf.format(a.get(i).getBirthday()));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void export0() {
		try {
			List<DemoEntity> s = new ArrayList<DemoEntity>();
			for (int i = 1; i <= 100; i++) {
				s.add(new DemoEntity("name-" + i, "desc-" + i, i, i * 0.01, new Date()));
			}
//			new ExcelExport().createExcel(new FileOutputStream(new File("D:\\22222.xlsx")), s, DemoEntity.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void export1() {
		try {
			List<DemoEntity> s = new ArrayList<DemoEntity>();
			for (int i = 1; i <= 100; i++) {
				s.add(new DemoEntity("name-" + i, "desc-" + i, i, i * 0.01, new Date()));
			}
//			new ExcelExport().createExcel(new FileOutputStream(new File("C:\\MyProject\\22222_combox.xlsx")), s, DemoEntity.class, "xx", new ExcelExportCallback() {
//
//				@Override
//				public void call(Sheet sheet) {
//					// 下拉数据
//					String[] strs = new String[] { "name-20[^111^]", "name-25[^222^]" };
//					XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet) sheet);
//					XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(strs);
//					// 显示位置(起始行/结束行/起始列/结束列)
//					CellRangeAddressList addressList = new CellRangeAddressList(1, 65535, 0, 1);
//					XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList);
//					// 错误提示
//					validation.setShowErrorBox(true);
//					// 添加
//					sheet.addValidationData(validation);
//				}
//
//			});
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
